#include "ffmpeg_video_queue.h"

videoQueue::videoQueue()
{
    cout << "this is videoQueue init..." << endl;
    pthread_mutex_init(&queue_mutex, NULL);
    pthread_cond_init(&queue_cond, NULL);
}

videoQueue::~videoQueue()
{
    cout << "this is videoQueue destroyed..." << endl;
    pthread_mutex_destroy(&queue_mutex);
    pthread_cond_destroy(&queue_cond);
}

int videoQueue::putVideoDataToQueue(video_data_packet *video_packet)
{
    pthread_mutex_lock(&queue_mutex);
    video_queue.push(video_packet);
    pthread_cond_broadcast(&queue_cond);
    pthread_mutex_unlock(&queue_mutex);
    return 0;
}

video_data_packet *videoQueue::getVideoDataFromQueue()
{
    pthread_mutex_lock(&queue_mutex);
    while (video_queue.empty())
    {
        pthread_cond_wait(&queue_cond, &queue_mutex);
    }
    video_data_packet *tmp_packet = video_queue.front(); // 此处队列里面的video数据是的new出来的！
    video_queue.pop();
    pthread_mutex_unlock(&queue_mutex);
    return tmp_packet;
}

int videoQueue::getVideoQueueSize()
{
    int size = -1;
    pthread_mutex_lock(&queue_mutex);
    size = video_queue.size();
    pthread_mutex_unlock(&queue_mutex);
    return size;
}